//
//  OrderDetailFooterView.m
//  PigMarket
//
//  Created by 张敬 on 2019/9/11.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "OrderDetailFooterView.h"

#define mGap TJ_SafeAreaBottomHeight/8.0

@interface OrderDetailFooterView()

@property (nonatomic, assign) CGFloat gap1;
@property (nonatomic, assign) CGFloat gap2;
@property (nonatomic, assign) CGFloat gap3;

@end

@implementation OrderDetailFooterView

#pragma mark - lifecycle methods

- (void)setupUI
{
    [self addSubview:self.goingBrowseBtn];
    [self addSubview:self.moreBtn];
    [self addSubview:self.PayBtn];
    [self addSubview:self.logisticsBtn];
    [self addSubview:self.evaluationBtn];
    [self addSubview:self.againEvaluationBtn];
    [self addSubview:self.okAcceptBtn];
    [self addSubview:self.FriendPayBtn];
    [self addSubview:self.cancelOrderBtn];
    [self addSubview:self.label];
    
}


- (void)setupLayout
{
    self.height = 50 + TJ_SafeAreaBottomHeight/2.0;
    
    CGSize size = CGSizeMake(76, 26 +TJ_SafeAreaBottomHeight/4.0 );
    CGFloat h = self.height;
    CGFloat w = KScreenWidth;
    CGFloat top = h/2.0 - 13;
    
    CGFloat _gap1 = w - (76 + 15);
    _gap2 = _gap1 - (76 + 10);
    _gap3 = _gap2 - (76 + 10);

    
    {
        _goingBrowseBtn.size = _logisticsBtn.size = _okAcceptBtn.size = size;
        _PayBtn.size = _evaluationBtn.size = _againEvaluationBtn.size = size;
        _FriendPayBtn.size = _cancelOrderBtn.size = _moreBtn.size = size;
    }
    
    {
        _goingBrowseBtn.mj_y = _logisticsBtn.mj_y = _okAcceptBtn.mj_y = top;
        _PayBtn.mj_y = _evaluationBtn.mj_y = _againEvaluationBtn.mj_y = top;
        _FriendPayBtn.mj_y = _cancelOrderBtn.mj_y = _moreBtn.mj_y = top;
        
    }
    
    
    {
        _moreBtn.mj_x = 15;
        
        _goingBrowseBtn.mj_x = _PayBtn.mj_x = _okAcceptBtn.mj_x = _gap1;
        _FriendPayBtn.mj_x = _evaluationBtn.mj_x = _againEvaluationBtn.mj_x = _logisticsBtn.mj_x = _gap2;
        
        _cancelOrderBtn.mj_x = _gap3;
    }
    
    
    {
        _label.size = CGSizeMake(w, h);
        _label.mj_x = _label.mj_y = 0;
    }
    
    {
        CAShapeLayer *line = [CAShapeLayer layer];
        line.fillColor = mIconLineColor.CGColor;
        UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, w, 0.5)];
        line.path = path.CGPath;
        [self.layer addSublayer:line];
    }
    
}


#pragma mark - setter methods

- (void)setOrderStateType:(OrderStateType)orderStateType{
    
    
    switch (orderStateType) {
        case OrderStateTyp_NoPaying: //待付款
        {
            _goingBrowseBtn.hidden = YES;
            _evaluationBtn.hidden = YES;
            _againEvaluationBtn.hidden = YES;
            _okAcceptBtn.hidden = YES;
            _cancelOrderBtn.hidden = NO;
            _logisticsBtn.hidden = YES;
            _FriendPayBtn.hidden = NO;
            _PayBtn.hidden = NO;
            _moreBtn.hidden = NO;
            _label.hidden = YES;
            
        }
            break;
            
        case OrderStateType_NoSending: //待发货
        {
            
            _goingBrowseBtn.hidden = YES;
            _evaluationBtn.hidden = YES;
            _againEvaluationBtn.hidden = YES;
            _okAcceptBtn.hidden = YES;
            _cancelOrderBtn.hidden = YES;
            _logisticsBtn.hidden = YES;
            _FriendPayBtn.hidden = YES;
            _PayBtn.hidden = YES;
            _moreBtn.hidden = NO;
            _label.hidden = NO;
            
            
        }
            break;
            
        case OrderStateType_NoAccept: //待收货
        {
            _goingBrowseBtn.hidden = YES;
            _evaluationBtn.hidden = YES;
            _againEvaluationBtn.hidden = YES;
            _okAcceptBtn.hidden = NO;
            _cancelOrderBtn.hidden = YES;
            _logisticsBtn.hidden = NO;
            _FriendPayBtn.hidden = YES;
            _PayBtn.hidden = YES;
            _moreBtn.hidden = NO;
            _label.hidden = YES;
            
        }
            break;
            
            
        case OrderStateType_NoEvaluation: //待评价
        {
            _goingBrowseBtn.hidden = NO;
            _evaluationBtn.hidden = NO;
            _againEvaluationBtn.hidden = YES;
            _okAcceptBtn.hidden = YES;
            _cancelOrderBtn.hidden = YES;
            _logisticsBtn.hidden = YES;
            _FriendPayBtn.hidden = YES;
            _PayBtn.hidden = YES;
            _moreBtn.hidden = NO;
            _label.hidden = YES;
            
        }
            break;
            
        case OrderStateType_Cancel: //已取消
        {
            _goingBrowseBtn.hidden = NO;
            _evaluationBtn.hidden = YES;
            _againEvaluationBtn.hidden = YES;
            _okAcceptBtn.hidden = YES;
            _cancelOrderBtn.hidden = YES;
            _logisticsBtn.hidden = YES;
            _FriendPayBtn.hidden = YES;
            _PayBtn.hidden = YES;
            _moreBtn.hidden = YES;
            _label.hidden = YES;
        }
            break;
            
            
        default: //已完成
        {
            _goingBrowseBtn.hidden = NO;
            _evaluationBtn.hidden = YES;
            _againEvaluationBtn.hidden = NO;
            _okAcceptBtn.hidden = YES;
            _cancelOrderBtn.hidden = YES;
            _logisticsBtn.hidden = YES;
            _FriendPayBtn.hidden = YES;
            _PayBtn.hidden = YES;
            _moreBtn.hidden = NO;
            _label.hidden = YES;
            
        }
            break;
    }
}


#pragma mark - getter methods

- (UIButton *)goingBrowseBtn{
    
    if (!_goingBrowseBtn) {
        _goingBrowseBtn = [UIButton makeButtonWithText:@"继续逛逛" textColor:mMainColor font:mMediumFont(13) textAliment:1 cornerRadius:13 + mGap];
        _goingBrowseBtn.layer.borderColor = mMainColor.CGColor;
        _goingBrowseBtn.layer.borderWidth = 1;
        
        @weakify(self);
        _goingBrowseBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealBrowseOrderBlock) {
                self.dealBrowseOrderBlock();
            }
        };
    }
    return _goingBrowseBtn;
}


- (UIButton *)PayBtn{
    
    if (!_PayBtn) {
        _PayBtn = [UIButton makeButtonWithText:@"去支付" textColor:mMainColor font:mMediumFont(13) textAliment:1 cornerRadius:13+mGap];
        _PayBtn.layer.borderColor = mMainColor.CGColor;
        _PayBtn.layer.borderWidth = 1;
        
        @weakify(self);
        _PayBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealPayOrderBlock) {
                self.dealPayOrderBlock();
            }
        };
    }
    return _PayBtn;
}


- (UIButton *)FriendPayBtn{
    
    if (!_FriendPayBtn) {
        _FriendPayBtn = [UIButton makeButtonWithText:@"朋友代付" textColor:UIColorFromRGB(0x454545) font:mMediumFont(13) textAliment:1 cornerRadius:13 +mGap];
        _FriendPayBtn.layer.borderColor = UIColorFromRGB(0xD8D8D8).CGColor;
        _FriendPayBtn.layer.borderWidth = 1;
        
        @weakify(self);
        _FriendPayBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealFriendPayOrderBlock) {
                self.dealFriendPayOrderBlock();
            }
        };
    }
    return _FriendPayBtn;
}

- (UIButton *)cancelOrderBtn{
    
    if (!_cancelOrderBtn) {
        _cancelOrderBtn = [UIButton makeButtonWithText:@"取消订单" textColor:UIColorFromRGB(0x454545) font:mMediumFont(13) textAliment:1 cornerRadius:13 +mGap];
        _cancelOrderBtn.layer.borderColor = UIColorFromRGB(0xD8D8D8).CGColor;
        _cancelOrderBtn.layer.borderWidth = 1;
        
        
        @weakify(self);
        _cancelOrderBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealCancelOrderBlock) {
                self.dealCancelOrderBlock();
            }
        };
        
    }
    return _cancelOrderBtn;
}


- (UIButton *)logisticsBtn{
    
    if (!_logisticsBtn) {
        _logisticsBtn = [UIButton makeButtonWithText:@"冷链物流" textColor:UIColorFromRGB(0x454545) font:mMediumFont(13) textAliment:1 cornerRadius:13 + mGap];
        _logisticsBtn.layer.borderColor = UIColorFromRGB(0xD8D8D8).CGColor;
        _logisticsBtn.layer.borderWidth = 1;
        
        @weakify(self);
        _logisticsBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealLogisticsOrderBlock) {
                self.dealLogisticsOrderBlock();
            }
        };
        
    }
    return _logisticsBtn;
}


- (UIButton *)evaluationBtn{
    
    if (!_evaluationBtn) {
        _evaluationBtn = [UIButton makeButtonWithText:@"晒单评价" textColor:UIColorFromRGB(0x454545) font:mMediumFont(13) textAliment:1 cornerRadius:13 + mGap];
        _evaluationBtn.layer.borderColor = UIColorFromRGB(0xD8D8D8).CGColor;
        _evaluationBtn.layer.borderWidth = 1;
        
        @weakify(self);
        _evaluationBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealEvaluationOrderBlock) {
                self.dealEvaluationOrderBlock();
            }
        };
    }
    return _evaluationBtn;
}


- (UIButton *)againEvaluationBtn{
    
    if (!_againEvaluationBtn) {
        _againEvaluationBtn = [UIButton makeButtonWithText:@"追加评价" textColor:UIColorFromRGB(0x454545) font:mMediumFont(13) textAliment:1 cornerRadius:13 + mGap];
        _againEvaluationBtn.layer.borderColor = UIColorFromRGB(0xD8D8D8).CGColor;
        _againEvaluationBtn.layer.borderWidth = 1;
        
        @weakify(self);
        _againEvaluationBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealAgainEvaluationOrderBlock) {
                self.dealAgainEvaluationOrderBlock();
            }
        };
    }
    return _againEvaluationBtn;
}


- (UIButton *)okAcceptBtn{
    
    if (!_okAcceptBtn) {
        _okAcceptBtn = [UIButton makeButtonWithText:@"确认收货" textColor:UIColorFromRGB(0x454545) font:mMediumFont(13) textAliment:1 cornerRadius:13 + mGap];
        _okAcceptBtn.layer.borderColor = UIColorFromRGB(0xD8D8D8).CGColor;
        _okAcceptBtn.layer.borderWidth = 1;
        
        @weakify(self);
        _okAcceptBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealOkAcceptBlock) {
                self.dealOkAcceptBlock();
            }
        };
    }
    return _okAcceptBtn;
}


- (UILabel *)moreBtn{
    
    if (!_moreBtn) {
        _moreBtn = [UILabel makeLabelWithText:@"更多" textColor:UIColorFromRGB(0x454545) font:mFont(13) textAliment:0];
        
        @weakify(self);
        _moreBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealMoreOperationBlock) {
                self.dealMoreOperationBlock();
            }
        };
    }
    return _moreBtn;
}


- (UILabel *)label{
    if (!_label) {
        _label = [[UILabel alloc] init];
        _label.textAlignment = NSTextAlignmentRight;
    }
    return _label;
}


@end
